package com.ruoyi.system.service.waterService.waterServiceImpl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.waterEnity.BuildingEntity;
import com.ruoyi.system.domain.waterEnity.DistributionInfoBo;
import com.ruoyi.system.mapper.waterMapper.DistributionMapper;
import com.ruoyi.system.service.waterService.DistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DistributionServiceImpl implements DistributionService {
    @Autowired
    private DistributionMapper distributionMapper;
    @Override
    public List<DistributionInfoBo> selectDistribution() {
        return  distributionMapper.selectDistribution();
    }

    @Override
    public List<DistributionInfoBo> selectDistributionByState(String state) {
        return distributionMapper.selectDistributionByState(state);
    }

    @Override
    public List<DistributionInfoBo> selectDistributionByPhone(String phone) {
        return distributionMapper.selectDistributionByPhone(phone);
    }

    @Override
    public List<DistributionInfoBo> selectDistributionByBuilding(String building) {
        return distributionMapper.selectDistributionByBuilding(building);
    }

    @Override
    public int updateOrderState(int state) {

        return distributionMapper.updateOrderState(state);
    }

    @Override
    public int deleteOrderByID(int id) {
        return distributionMapper.deleteOrderByID(id);
    }

    @Override
    public List<DistributionInfoBo> selectAllDistrition(String phone, String building, String state) {
        String flag= phone+ building + state + state ;
        List<DistributionInfoBo> list = null;
        if (StringUtils.isEmpty(flag)){
            list = distributionMapper.selectDistribution();
        }else if (StringUtils.isNotEmpty(phone)){
            list = distributionMapper.selectDistributionByPhone(phone);
        }else if (StringUtils.isNotEmpty(building)){
            list = distributionMapper.selectDistributionByBuilding(building);
        }else if (StringUtils.isNotEmpty(state)){
            list = distributionMapper.selectDistributionByState(state);
        }
        else{
            list = distributionMapper.selectDistribution();
        }
        return list;
    }

    @Override
    public List<DistributionInfoBo> selectOrderByIds(String ids) {
        Long[] dis = Convert.toLongArray(ids);
        List<DistributionInfoBo> num = distributionMapper.selectOrderByIds(dis);
        return num;
    }

    @Override
    public int deleteOrderByIds(String ids) {
        Long[] dis = Convert.toLongArray(ids);
        return distributionMapper.deleteOrderByIds(dis);
    }

    @Override
    public List<BuildingEntity> selectBuilding() {
        return distributionMapper.selectBuilding();
    }

}
